<template>
  <div>
    <div class="container">
      <div class="item" v-for="(item, index) in topList" :key="index">
        <div class="pic">
          <img :src="item.picUrl" alt="">
          <div class="cover">
            <i class="el-icon-video-play"></i>
          </div>
        </div>
        <div class="right">
          <div class="title">{{ item.topTitle }}</div>
          <div class="list" v-for="(song, index) in item.songList" :key="index">
            {{ index + 1 }} {{ song.songname }} - {{ song.singername }}
          </div>
        </div>
      </div>
    </div>
    <h3>地区榜</h3>
    <div class="box">
      <div v-for="(item, index) in areaList" :key="index">
        <div class="pic">
          <img :src="item.picUrl" alt="">
          <div class="cover">
            <i class="el-icon-video-play"></i>
          </div>
        </div>
      </div>
    </div>
    <h3>特色榜</h3>
    <div class="box">
      <div v-for="(item, index) in specialList" :key="index">
        <div class="pic">
          <img :src="item.picUrl" alt="">
          <div class="cover">
            <i class="el-icon-video-play"></i>
          </div>
        </div>
      </div>
    </div>
    <h3>全球榜</h3>
    <div class="box">
      <div class="item" v-for="(item, index) in globalList" :key="index">
        <div class="pic">
          <img :src="item.picUrl" alt="">
          <div class="cover">
            <i class="el-icon-video-play"></i>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getTopRank } from '@/service/music';

export default {
  data() {
    return {
      rankList: [],
      topList: [],
      areaList: [],
      specialList: [],
      globalList: [],
    };
  },
  methods: {
    async getTopRankData() {
      const res = await getTopRank();
      const { code, data } = res || {};
      if (code) return;
      this.rankList = data.topList || [];
      this.topList = data.topList.filter((item) => {
        return (item.topTitle.indexOf('飙升') !== -1) || (item.topTitle.indexOf('巅峰榜·新歌') !== -1) ||(item.topTitle.indexOf('巅峰榜·热歌') !== -1) ||
        (item.topTitle.indexOf('流行') !== -1) || (item.topTitle.indexOf('喜力') !== -1) || (item.topTitle.indexOf('腾讯') !== -1) ||
        (item.topTitle.indexOf('听歌') !== -1) || (item.topTitle.indexOf('MV') !== -1)
      });
      this.areaList = data.topList.filter((item) => {
        return (item.topTitle.indexOf('内地') !== -1) || (item.topTitle.indexOf('香港') !== -1) || (item.topTitle.indexOf('台湾') !== -1) ||
        (item.topTitle.indexOf('欧美') !== -1) || (item.topTitle.indexOf('日本') !== -1) || (item.topTitle.indexOf('韩国') !== -1);
      });
      this.specialList = data.topList.filter((item) => {
        return (item.topTitle.indexOf('网络歌曲') !== -1) || (item.topTitle.indexOf('DJ舞曲') !== -1) || (item.topTitle.indexOf('抖快榜') !== -1) ||
        (item.topTitle.indexOf('综艺新歌') !== -1) || (item.topTitle.indexOf('国风热歌') !== -1) || (item.topTitle.indexOf('说唱') !== -1) ||
        (item.topTitle.indexOf('动漫') !== -1) || (item.topTitle.indexOf('游戏') !== -1) || (item.topTitle.indexOf('全民') !== -1)||
        (item.topTitle.indexOf('达人音乐榜') !== -1);
      })
      this.globalList = data.topList.filter((item) => {
        return this.topList.indexOf(item) === -1 && this.areaList.indexOf(item) === -1 && this.specialList.indexOf(item) === -1
      })
    },
  },
  mounted() {
    this.getTopRankData();
  },
};
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  background: url(https://img0.baidu.com/it/u=570632264,2705503034&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500) no-repeat;
  background-size: contain;
  border-radius: 10px;
  .item {
    // min-width: 20%;
    width: 350px;
    height: 120px;
    display: flex;
    background-color: rgba(10, 10, 10, .3);
    margin-top: 10px;
    border-radius: 10px;
    cursor: pointer;
    &:hover {
      transform: translateY(-5%);
    }
    .pic {
      position: relative;
      width: 120px;
      &:hover {
        .cover {
          display: block;
        }
      }
      img {
        width: 120px;
        border-radius: 10px;
      }
    }
    .cover {
      position: absolute;
      top: 0;
      left: 0;
      width: 120px;
      height: 120px;
      border-radius: 10px;
      display: none;
      text-align: center;
      line-height: 120px;
      font-size: 40px;
      background-color: rgba(0, 0, 0, .6);
      color: #fff;
      i {
        &:hover {
          color: pink;
        }       
      }
    }
    .right {
      margin-top: 20px;
      margin-left: 10px;
      overflow: hidden;
      padding-right: 10px;
      box-sizing: border-box;
      .title {
        color: #fff;
        font-weight: 600;
      }
      .list {
        font-size: 12px;
        color: #ccc;
        margin: 5px 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
    transition: all 0.2s;
  }
}
h3 {
  color: pink;
}
.box {
  display: flex;
  // justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 80px;
  .pic {
    margin-right: 10px;
    margin-bottom: 10px;
    &:hover {
      transform: translateY(-5%);
    }
    position: relative;
    width: 120px;
    &:hover {
      .cover {
        display: block;
      }
    }
    img {
      width: 100%;
      border-radius: 10px;
    }
    transition: all 0.2s;
  }
  .cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 120px;
    border-radius: 10px;
    display: none;
    text-align: center;
    line-height: 120px;
    font-size: 40px;
    background-color: rgba(0, 0, 0, .6);
    color: #fff;
    i {
      &:hover {
        color: pink;
      }       
    }
  }
}
</style>
